<?php include "include/function_library.php"; ?>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>

<?php include "html/header.html"; ?>

</head>
<body class="tcuk home">

	<div id="wp">
	
		<?php  include "html/menu.html"; ?>
		
		<!-- CONTENT STARTS-->
		<div id="ct">
			<?php if(get("deleted") == "1") echo "<div class='alert success'>Hotel Deleted Successfully!</div>"; ?>
			
			<div id="query_area">
				<!--  Query Area Html Part -->
				<fieldset>
				<legend>&nbsp;&nbsp;Filter results:</legend>
				<form action="<?php echo curPageURL(); ?>" method="post">
					<input type="text" name="q_name" id="q_name" placeholder="Hotel Name" />
					
					<input type="text" name="q_city" id="q_city" placeholder="City or District" />
					
					<input type="text" name="q_price" id="q_price" placeholder="Max Price" />
					
					<select name="q_type" id="q_type">
						<option value="All">Hotel Type</option>
						<option value="Small hotel">Small hotel</option>
						<option value="Medium sized hotel">Medium sized hotel</option>
						<option value="Large hotel">Large hotel</option>
						<option value="Mega hotel">Mega hotel</option>
						<option value="Chain hotel">Chain hotel</option>
					</select>
					
					<input type="submit" name="q_search" id="q_search" value="Search"/>
				</form>
				</fieldset>
				<?php 
					/* Query Area Php Part */
					$query = "SELECT h.id, h.name, h.tel, h.capacity, h.type, h.price, a.city, a.district FROM hotel h, address a WHERE h.address_id=a.id ";
					
					if(post("q_search")) {
						$q_name 	= post("q_name");
						$q_city 	= post("q_city");
						$q_price 	= post("q_price");
						$q_type 	= post("q_type");
						
						if($q_name != "") $query .= "AND h.name LIKE '%$q_name%' ";
						if($q_city != "") $query .= "AND (a.city LIKE '%$q_city%' OR a.district LIKE '%$q_city%') ";
						if($q_price != "") $query .= "AND h.price <= '$q_price' ";
						if($q_type != "" && $q_type != "All") $query .= "AND h.type = '$q_type' ";
					}
				?>
			</div>
			
			<table border="" style="margin-top: 0px;">
			<thead>
				<tr>
					<th>Name</th>
					<th>Phone</th>
					<th>Capacity</th>
					<th>Type</th>
					<th>Address</th>
					<th>Price</th>
				</tr>
			</thead>
			<tbody>
				<?php 
					$result = sql_query($query);
					while($tuple = mysql_fetch_assoc($result)) {
						?>
						<tr>
							<td><a href="hotel_detail.php?id=<?php echo $tuple["id"]; ?>"><?php echo $tuple["name"]; ?></a></td>
							<td><?php echo $tuple["tel"]; ?></td>
							<td><?php echo $tuple["capacity"]; ?></td>
							<td><?php echo $tuple["type"]; ?></td>
							<td><?php echo $tuple["city"];?> / <?php echo $tuple["district"]; ?></td>
							<td><?php echo $tuple["price"]; ?></td>
						</tr>
						<?php
					}
				?>
			</tbody>
			</table>
		
		</div> 	
		<!-- CONTENT ENDS-->		
		
		<?php include "html/footer.html"; ?>
		
	</div>
	
</body>
</html>